package cn.fl.grpcfg.service.impl;

import java.util.List;
import java.util.Map;

import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.logger.eum.LogOperEnum;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.grpcfg.service.ISplGroupCfgDtlService;
import cn.fl.grpcfg.transform.SplGroupCfgDtlVOTransform;
import cn.fl.grpcfg.vo.SplGroupCfgDtlVO;
import fl.constant.facade.framework.constant.BusinessIdConstant;
import fl.spl.facade.framework.constant.SplSystemConstant;
import fl.spl.facade.grpcfg.api.ISplGroupCfgDtlApiService;
import fl.spl.facade.grpcfg.condition.SplGroupCfgDtlQC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import fl.spl.facade.grpcfg.dto.SplGroupCfgDtlDTO;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cmm.mid.core.framework.page.Pager;


/**
 * @Description: 集团管理划分配置表 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class SplGroupCfgDtlServiceImpl implements ISplGroupCfgDtlService {

	/**
	 * 自定义 API 自行注入需要的API服务
	 */
	@Autowired
	private ISplGroupCfgDtlApiService splGroupCfgDtlApiService ;

	@Override
	public SplGroupCfgDtlVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			throw new BaseException(BaseExceptionConstant.COMMON_0001, "获取对象主键不能为空!");
		}
		//TODO 业务逻辑
		SplGroupCfgDtlDTO dto = null;//this.自定义ApiService.selectSplGroupCfgDtlDTOById(id);
		return SplGroupCfgDtlVOTransform.toVO(dto);
	}

	@Override
	public Long add(SplGroupCfgDtlVO entity) throws BaseException{
		if(null == entity){
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"新增对象不存在!");
		}
		return this.splGroupCfgDtlApiService.addSplGroupCfgDtl(SplGroupCfgDtlVOTransform.toDTO(entity), SplSystemConstant.FL_SYS_CD,SplSystemConstant.DEFAULT_ORG_CD,SplSystemConstant.FL_WEB_CHL_CD);
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"删除对象主键不能为空!");
		};
		//return this.splGroupCfgDtlApiService.removeSplGroupCfgDtlDTOById(id);
		//TODO 业务逻辑
		return false;
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
	@Override
    public boolean removeByIds(List<Long> ids)throws BaseException{
		if(CollectionUtils.isEmpty(ids)){
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"删除对象主键不能为空!");
		};
		return false;
    }

	@Override
	public boolean modify(SplGroupCfgDtlVO entity) throws BaseException{
		if(null == entity){
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"修改对象不能为空!");
		};
		//return this.splGroupCfgDtlApiService.modifySplGroupCfgDtlDTO(SplGroupCfgDtlVOTransform.toDTO(entity));
		//TODO 业务逻辑
		return false;
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page){
			page = new Pager();
		}
		//return this.splGroupCfgDtlApiService.searchSplGroupCfgDtlListPage(page);
		//TODO 业务逻辑
		return null;
	}

	/**
	 * 根据条件查询所有
	 *
	 * @param cfgDtlQC
	 * @return
	 */
	@Override
	public List<SplGroupCfgDtlVO> searchList(SplGroupCfgDtlQC cfgDtlQC) throws BaseException {
		if(null == cfgDtlQC){
			cfgDtlQC = new SplGroupCfgDtlQC();
		}
		return SplGroupCfgDtlVOTransform.toVOList(this.splGroupCfgDtlApiService.searchSplGroupCfgDtlDTOList(cfgDtlQC));
	}

	/**
	 * 修改新增新配置信息操作
	 *
	 * @param qc
	 * @param dtlDTO
	 * @param mdfMap
	 * @return
	 * @throws BaseException
	 */
	@Override
	public boolean mdfAndAddSplGrpCfgDtl(SplGroupCfgDtlQC qc, SplGroupCfgDtlDTO dtlDTO, Map<String, Object> mdfMap) throws BaseException {
		if(null == qc){
			BaseLogUtils.newWebLogger("修改集团配置信息条件QC为空!").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001,BaseExceptionConstant.COMMON_0001_NAME);
		}
		if(null == dtlDTO){
			BaseLogUtils.newWebLogger("新增集团划分配置信息为空!").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001,BaseExceptionConstant.COMMON_0001_NAME);
		}
		if(CollectionUtils.isMapEmpty(mdfMap)){
			BaseLogUtils.newWebLogger("需修改的集团配置信息为空!").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001,BaseExceptionConstant.COMMON_0001_NAME);
		}
		return this.splGroupCfgDtlApiService.mdfAndAddSplGrpCfgDtl(qc,dtlDTO,mdfMap);
	}
}
